package com.websystique.springsecurity.service;

import com.websystique.springsecurity.dao.UserDao;
import com.websystique.springsecurity.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("userService")
@Transactional
public class UserServiceImpl implements  UserService {
    @Autowired
    private UserDao userDao;

    @Autowired
    private PasswordEncoder passwordEncoder;
    @Override
    public User findById(int id) {
        return userDao.findById(id);
    }

    @Override
    public User findBySso(String sso) {
        return userDao.findBySSO(sso);
    }

    @Override
    public boolean save(User user){
        boolean b=false;
        try {
            user.setPassword(passwordEncoder.encode(user.getPassword()));
            userDao.save(user);
            b=true;
        }catch (Exception e){}
        return b;
    }
}
